//
//  HideWebViewController.m
//  LOL_PalmarHelper
//
//  Created by dlios on 15-6-27.
//  Copyright (c) 2015年 hantao. All rights reserved.
//

#import "HideWebViewController.h"

@interface HideWebViewController ()

@end

@implementation HideWebViewController
- (void)dealloc
{
    [_myWeb release];
    [_myurl release];
    [_hud release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"隐藏分查询";
    
    
    
    self.myWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 115)];
    
    
    NSString *urlstr = self.myurl;
    
    NSURL *url = [NSURL URLWithString:urlstr];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [self.view addSubview:self.myWeb];
    
    self.myWeb.delegate = self;
    
    [self.myWeb loadRequest:request];
    
    [self.myWeb setScalesPageToFit:YES];// 自适应
    
    
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    
    [self.view addSubview:self.hud];
    
    self.hud.labelText = @"正在加载中";
    
    [self.hud show:YES];
    
    [_hud release];

    
    //2. 禁用拖拽时的反弹效果
    [(UIScrollView *)[[self.myWeb subviews] objectAtIndex:0] setBounces:NO];
    
    
    
    
    self.addpage = NO;
    
    [self.myWeb release];

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.myWeb reload];
}





- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    
    if (self.add == 1 && self.addpage == NO) {
        
        [self.myWeb stopLoading];
    }
    
    if (self.add == 1 && self.addpage == YES) {
        
        self.add = 0;
        
        self.addpage = NO;
        
   
    }
    
    
    
    return YES;
    
}

-(void)goBack
{
    
    [self.myWeb goBack];
    
}

- (void)pushBack
{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
}





- (void )webViewDidFinishLoad:(UIWebView  *)webView  //网页加载完成的时候调用
{
    
    
    self.addpage = YES;
    
    [self.hud hide:YES];
    
    
    
    
}

//  网页加载开始的时候调用

//- (void)webViewDidStartLoad:(UIWebView  *)webView   //网页开始加载的时候调用
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    
    
    self.add = 1;
    
    
    
//    NSLog(@"开始加载");
    
    
    
}


- (void)webView:(UIWebView *)webView  didFailLoadWithError:(NSError *)error //网页加载错误的时候调用
{
    
    
    [self.hud hide:YES];
//    NSLog(@"加载错误");
    
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
